package com.samehope.ar.controller;


import com.samehope.ar.common.CommonResult;
import com.samehope.ar.dto.PaginationParam;
import com.samehope.ar.dto.PatrolTaskPlanUpdateParam;
import com.samehope.ar.dto.TaskNormalUpdateParam;
import com.samehope.ar.dto.TaskQueryParam;
import com.samehope.ar.service.ITaskNormalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 正式巡检任务 前端控制器
 * </p>
 *
 * @author Zhang Luo
 * @since 2019-12-23
 */
@RestController
@RequestMapping("/taskNormal")
public class TaskNormalController {

    @Autowired
    private ITaskNormalService taskNormalService;

    /**
     * 分页获取任务执行时间列表
     * @param paginationParam
     * @param param
     * @return
     */
    @GetMapping("/pageList")
    public CommonResult pageList(@Valid PaginationParam paginationParam, TaskQueryParam param){
        return CommonResult.success(taskNormalService.findByParam(paginationParam, param));
    }

    @PreAuthorize("hasRole('ROLE_PROJECT')")
    @PutMapping("/update")
    public CommonResult update(@RequestBody @Valid TaskNormalUpdateParam param){
        taskNormalService.update(param);
        return CommonResult.success(null);
    }

    @PreAuthorize("hasRole('ROLE_PROJECT')")
    @DeleteMapping("/del/{taskId}")
    public CommonResult del(@PathVariable Long taskId){
        taskNormalService.del(taskId);
        return CommonResult.success(null);
    }

    @GetMapping("/detail/{taskId}")
    public CommonResult detail(@PathVariable("taskId") Long taskId){
        return CommonResult.success(taskNormalService.detail(taskId));
    }

    @GetMapping("/getTaskName")
    public CommonResult getTaskName(){
        return CommonResult.success(taskNormalService.getTaskName());
    }
}
